package edu.csl.study.springboot.core.book.controller;

import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/book")
@Log4j2
public class BookController {
    @PostMapping("/")
    @ApiOperation("index")
    public  String index(Model model, HttpServletRequest request){
       model.addAttribute("tip","欢迎一个Spring boot应用");
       HttpSession session = request.getSession();
       log.info(session.getClass());
       session.setAttribute("user","zhangsan");
       return "hello";
    }
    @PostMapping("/rest")
    @ApiOperation("rest")
    @ResponseBody
    public ResponseEntity restIndex(){
        return new ResponseEntity<>("欢迎一个Spring boot应用",null, HttpStatus.OK);
    }
}
